package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.GroupTravel;
import cn.wolfcode.luowowo.article.mapper.GroupTravelMapper;
import cn.wolfcode.luowowo.article.service.IGroupTravelService;
import cn.wolfcode.luowowo.common.query.GroupTravelQueryObject;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class GroupTravelServiceImpl implements IGroupTravelService{
    @Autowired
    private GroupTravelMapper groupTravelMapper;

    public PageInfo query(GroupTravelQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<GroupTravel> list = groupTravelMapper.selectForList(qo);
        return new PageInfo(list);
    }

    public void deleteById(Long id) {
        groupTravelMapper.deleteByPrimaryKey(id);
    }

    public void saveOrUpdate(GroupTravel groupTravel) {
        if(groupTravel.getId() == null){
            //新增操作
            groupTravelMapper.insert(groupTravel);
        }else{
            //更新操作
            groupTravelMapper.updateByPrimaryKey(groupTravel);
        }
    }

    public List<GroupTravel> selectAll() {

        return groupTravelMapper.selectAll();
    }

    public List<GroupTravel> selectTop5Sales() {

        return groupTravelMapper.selectTop5Sales();
    }
}
